<template>
	<view class="catalog">
		<view class="catalog-list" v-for="(item,index) in chapterList" :key="index" @click="goRead(item.uuid)">
			{{item.title}}
		</view>
	</view>
</template>

<script>
	export default {
		name: 'catalog',
		data() {
			return {
				id: '',
				chapterList: [],
			};
		},
		onBackPress() {
			this.back();
			return true;
		},
		methods: {
			back(){
				uni.navigateTo({
					url:'../detail/detail?id='+this.id
				})
			},
			getChapter() {
				uni.request({
					url: `https://apis.netstart.cn/yunyuedu/reader/book/info.json?source_uuid=${this.id}`,
					method: 'GET'
				}).then(res => {
					// console.log('res ==> ', res);
					this.chapterList = res.data.data.catalog
					console.log('this.chapterList ==> ', this.chapterList);
					uni.hideLoading()
				}).catch(err => {
					console.log('err ==> ', err);
				})
			},
			goRead(id){
				uni.navigateTo({
					url:`../read/read?bookId=${this.id}&catalogId=${id}`
				})
			},
		},
		onLoad(option) {
			uni.showLoading({
				title: '正在加载中...'
			});
			// console.log(option);
			this.id = option.id;
			this.getChapter();
		}
	}
</script>

<style lang="scss">
	.catalog-list{
		background-color: #FCECCC;
		width: 100%;
		height: 94rpx;
		border-bottom: 1px dotted #998D80;
		font-size: 28rpx;
		line-height: 94rpx;
		padding-left: 50rpx;
	}
</style>